#include "heapsort.h"
#include "mergesort.h"
#include "quicksort.h"
#include "stlsort.h"
#include "compare.h"

#include <assert.h>

#include <iostream>

using namespace std;

void testMerge(const vector<string> &input, const vector<string> &asc, const vector<string> &desc)
{
  assert(Merge<string>(input).sort() == asc);
  assert(Merge<string>(input,CompareMin<string>()).sort() == desc);
 
  assert(Merge<string>(asc).sort() == asc);
  assert(Merge<string>(desc,CompareMin<string>()).sort() == desc);

  assert(Merge<string>(desc).sort() == asc);
  assert(Merge<string>(asc,CompareMin<string>()).sort() == desc);
}

void testHeap(const vector<string> &input, const vector<string> &asc, const vector<string> &desc)
{
  assert(Heap<string>(input).sort() == asc);
  assert(Heap<string>(input,CompareMin<string>()).sort() == desc);
 
  assert(Heap<string>(asc).sort() == asc);
  assert(Heap<string>(desc,CompareMin<string>()).sort() == desc);

  assert(Heap<string>(desc).sort() == asc);
  assert(Heap<string>(asc,CompareMin<string>()).sort() == desc);
}

void testQuick(const vector<string> &input, const vector<string> &asc, const vector<string> &desc)
{
  assert(Quick<string>(input).sort() == asc);
  assert(Quick<string>(input,CompareMin<string>()).sort() == desc);
 
  assert(Quick<string>(asc).sort() == asc);
  assert(Quick<string>(desc,CompareMin<string>()).sort() == desc);

  assert(Quick<string>(desc).sort() == asc);
  assert(Quick<string>(asc,CompareMin<string>()).sort() == desc);
}

void testSTLSort(const vector<string> &input, const vector<string> &asc, const vector<string> &desc)
{
  assert(STLSort<string>(input).sort() == asc);
  assert(STLSort<string>(input,CompareMin<string>()).sort() == desc);
 
  assert(STLSort<string>(asc).sort() == asc);
  assert(STLSort<string>(desc,CompareMin<string>()).sort() == desc);

  assert(STLSort<string>(desc).sort() == asc);
  assert(STLSort<string>(asc,CompareMin<string>()).sort() == desc);
}

int main()
{
# ifdef NDEBUG
#   warning "Os testes não serão executados. Para executá-los, compile com suporte a Debug"
  cerr << "Nenhum teste executado!" << endl;
  return 1; 
# else

  const vector<string> input {"Leandro","Maria","Ananias","Fernando","Zileide","Joaquim","Xavier","Irene","Barbara","Leandro","Kelyane","Paulo","Quintana"};
  
  const vector<string> asc {"Ananias","Barbara","Fernando","Irene","Joaquim","Kelyane","Leandro","Leandro","Maria","Paulo","Quintana","Xavier","Zileide"};

  const vector<string> desc {"Zileide","Xavier","Quintana","Paulo","Maria","Leandro","Leandro","Kelyane","Joaquim","Irene","Fernando","Barbara","Ananias"};

  testMerge(input,asc,desc);
  testHeap(input,asc,desc);
  testQuick(input,asc,desc);
  testSTLSort(input,asc,desc);

  cout << "Todos os testes passaram! Fodástico!" << endl;

  return 0;

# endif
}
